using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Tornadopro : MonoBehaviour
{
    // Start is called before the first frame update
    public int face;
    public float Runspeed;
    private Rigidbody2D myRigidbody;
    PlayerAttack playerattack;
    public float damageratio;
    public float survivetime;
    public int RepelTimes;
    public float RepelDistance, StiffTime;
    private PolygonCollider2D collider2D;
    private GameObject attackobject;
    void Start()
    {
        myRigidbody = GetComponent<Rigidbody2D>();
        collider2D = GetComponent<PolygonCollider2D>();
        attackobject = GameObject.FindWithTag("Attack");
        playerattack = attackobject.GetComponent<PlayerAttack>();
        face = playerattack.face;
    }
    private void OnTriggerStay2D(Collider2D other)
    {
        if (other.gameObject.CompareTag("Enemy"))
        {

            other.GetComponent<EnemyBasic>().TakeDamage(damageratio * playerattack.damage, face, RepelTimes, RepelDistance, StiffTime);
        }
        if (other.gameObject.CompareTag("GrindingTower"))
        {
            other.GetComponent<Grinding>().TakeDamage(damageratio * playerattack.damage);
        }
    }
    // Update is called once per frame
    void Update()
    {
        survivetime -= Time.deltaTime;
        if (survivetime <= 0)
        {
            Destroy(gameObject);
        }
        Vector2 vel = new Vector2(face * Runspeed, myRigidbody.velocity.y);
        myRigidbody.velocity = vel;
    }
}
